<?php
class TradeAction extends CommonAction{
    public function tradeshow(){
		$teade = new TradeModel($this->_get('id'));
		if(!$teade->BusinessProblemId)
			echo '<script>alert("非法进入");window.history.back(-1);</script>';
		$this->assign('teamofficer',$teade->teamofficer);	//该问题所属的企业的教官的信息
		$this->assign('Pb',$teade->getProbleminfo());		//竞赛项目的详细信息
		$this->assign('list',$teade->getselectedteam());	//选择该竞赛项目的团队
		
		// $ree=A('Public/Mail');
		
		R('Public/Mail/autosendmail',array(15),null);//测试无法远程跨分组调用方法，Why？？？
		
		// $res = new MailAction();
		// dump($res);
		$this->display();
    }
	
	//选择商业实现问题
	public function chosebp(){
		$bpid = $this->_post('id');
		if(!$teamid = $this->getmyteamid()){
			echo json_encode(array('res'=>false,'msg'=>'你还没创建团队,不能选择商业实践问题','id'=>null));
		}else{
			if(M()->query('select TeamId from project where TeamId ='.$teamid)){
				echo json_encode(array('res'=>false,'msg'=>'您已经选择过商业实践问题了，不能再选择。','id'=>null));
			}else{
				$nowtime=date('Y-m-d H:i:s');
				$eid = $this->_post('eid');
				if(($pjid=M()->execute('
					insert into project(ProjectType,ProblemId,EnterpriseId,TeamId,CreateTime,LastUpdate) values("企业项目",'.$$bpid.','.$eid.','.$teamid.',"'.$nowtime.'","'.$nowtime.'")
				')) && M()->execute('
					insert into juryproject(ProjectId,TeamId,Section) values('.$pjid.','.$teamid.',1)
				')){
					echo json_encode(array('res'=>true,'msg'=>'您已经成功选择此商业实践项目，是否跳转到该页面继续填写？','pjid'=>$pjid));
				}else{
					echo json_encode(array('res'=>false,'msg'=>'选择此商业实践问题失败，请重试。','id'=>null));
				}
			}
		}
	}
	
	//我的团队的ID
	public function getmyteamid(){
		$myid=$_SESSION[C('USER_AUTH_KEY')]['UserId'];
		$teaminfo=M()->query('select Id from team where Captain='.$myid);
		return $teaminfo[0]['Id'];
	}
}